<script setup lang="ts">
defineOptions({
  name: "checkListTitle"
});
import { ref, reactive } from "vue";
import { useRoute } from "vue-router";
import { CircleCheck } from "@px-ui/icons-vue";
import { computed } from "vue";

const route = useRoute();

interface Props {
  title?: string;
  collapse?: boolean;
  executor?: number | string | null;
  index?: number;
}

const props = withDefaults(defineProps<Props>(), {
  title: "",
  collapse: false,
  executor: null,
  index: 1
});

const isCompleted = computed(() => {
  const {
    query: { type = "add" }
  } = route;
  if (type === "add") {
    return false;
  } else {
    return !!props.executor;
  }
});
</script>

<template>
  <div class="checklist-title">
    <px-icon v-if="isCompleted"><CircleCheck /></px-icon>
    <div v-else :class="['checklist-index', collapse ? 'checklist-collapse' : '']">{{ index }}</div>
    <div class="title-text">{{ title }}</div>
  </div>
</template>

<style lang="scss" scoped>
.checklist-title {
  display: flex;
  gap: 6px;
  align-items: center;

  .px-icon {
    font-size: 24px;
    line-height: 1;
    color: var(--px-color-primary);
  }

  .checklist-index {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 22px;
    height: 22px;
    line-height: 1;
    color: #ccc;
    background-color: #fff;
    border: 1px solid #ccc;
    border-radius: 50%;
  }

  .checklist-collapse {
    color: #fff;
    background-color: var(--px-color-primary);
    border-color: var(--px-color-primary);
  }

  .title-text {
    font-weight: 500;
    line-height: 1;
    color: #333;
  }
}
</style>
